import "../static/libs/flexible"
import "../scss/common.scss"
import "../scss/finishTest.scss"
import http from "../utils/http"

async function main() {
    //获取考试页面转过来的id
    const testedId = location.search.substr(1).split("-")[0]
    const testId = location.search.substr(1).split("-")[1]

    console.log("testedId" + testedId, "testId" + testId);
    //发送请求
    const { data } = await http({ url: "/testeds/findById?id=" + testedId })
    console.log(data);
    //渲染
    render(data)
    //返回首页
    toHome(testedId, testId)
}
main()

//渲染
function render(data) {
    const userInfo = JSON.parse(localStorage.getItem("userInfo") || "{}")
    $(".container .warper").html(`
    <div class="icon">
        <img src="../static/images/tx1.png" alt="">
    </div>
    <div class="name">${userInfo.name}</div>
    <div class="score"><i id="fa1" class="fa fa-star"></i><span>${data.score}</span>分<i id="fa2" class="fa fa-star"></i></div>
    <div class="txt">考试已结束，感谢作答！</div>
    <div class="box">
        <div class="left">
            <p class="p1">${data.accuracy}%</p>
            <p class="p2">正确率</p>
        </div>
        <div class="right">
            <p class="p1">${data.durations}</p>
            <p class="p2">答题用时</p>
        </div>
    </div>
    <button id="check" type="button">查看解析</button>
    <button id="back" type="button">返回首页</button>
    `)
}

//点击返回首页
function toHome(testedId, testId) {
    $("#back").on("click", function () {
        window.location.assign("index.html")
    })
    $("#check").on("click", function () {
        window.location.assign("analysis.html?" + testedId)
    })
}

